import collections
class Solution(object):
    def frequencySort(self, s):
        """
        :type s: str
        :rtype: str
        """
        c = collections.Counter(s)
        stack = [[c[key], key] for key in c]
        stack.sort(reverse=True)
        t = ''
        for item in stack:
            t += item[1] * item[0]
        return t



data = Solution()
s = "tree"
print(data.frequencySort(s))